package org.scboy.dbms.controller;

import java.util.List;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.dbms.service.BaseAppServerService;
import org.scboy.utils.entitys.coobi.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/base/appserver")
@Menu("微服务管理系统.微服务部署管理")
public class BaseAppServerController {
	
	@Autowired
	BaseAppServerService service;
	
	@PostMapping("list")
	@Permission("分页查询")
	public Result list(@RequestBody Model params) {
		List<Model> datas=service.list(params);
		return Result.Success(datas);
	}
	

	@GetMapping("listAll")
	@Permission("所有部署的服务")
	public Result list() {
		List<Model> datas=service.listAll();
		return Result.Success(datas);
	}
	
	@PostMapping("addApp")
	@Permission("部署微服务")
	public Result addApp(@RequestBody Model params) {
		boolean result=service.addApp(params);
		if(result) {
			return Result.Success("BASE_APP_ADDAPP_SUCCESS");
		}else {
			return Result.Success("BASE_APP_ADDAPP_ERROR");
		}
	}

	@PostMapping("start")
	@Permission("获取服务器健康状态")
	public Result start(@RequestBody Model params) {
		String ip=params.getString("ip");
		String appName=params.getString("appName");
		String id=params.getString("id");
		service.start(ip,appName,id);
		return Result.Success("APP_SERVER_START_SUCCESS");
	}

	@PostMapping("restart")
	@Permission("获取服务器健康状态")
	public Result restart(@RequestBody Model params) {
		String ip=params.getString("ip");
		String appName=params.getString("appName");
		String id=params.getString("id");
		service.restart(ip,appName,id);
		return Result.Success("APP_SERVER_RESTART_SUCCESS");
	}

	@PostMapping("stop")
	@Permission("获取服务器健康状态")
	public Result stop(@RequestBody Model params) {
		String ip=params.getString("ip");
		String appName=params.getString("appName");
		String id=params.getString("id");
		service.stop(ip,appName,id);
		return Result.Success("APP_SERVER_STOP_SUCCESS");
	}
}
